package com.advaita.gui;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.border.TitledBorder;

import com.advaita.license.Customer;

public class ReferenceSetPanel extends JPanel implements ActionListener {

	static String string1 = "Microarray";
	static String string2 = "Whole Genome";
	static String string3 = "Custom Array";
	private Microarray microarrayPanel;
	GridBagConstraints c;
	Customer customer;
	
	ReferenceSetPanel(Customer myCustomer) {

		customer = myCustomer;
		setLayout(new GridBagLayout());
		c = new GridBagConstraints();

		Dimension size2 = getPreferredSize();
		size2.width = 250;
		size2.height = 350;
		setPreferredSize(size2);
		setBorder(BorderFactory.createTitledBorder(null, "Chose Reference Set",
				TitledBorder.LEFT, TitledBorder.TOP, new Font("Serif",
						Font.ITALIC + Font.BOLD, 20)));

		JRadioButton btn1 = new JRadioButton(string1);
		btn1.setActionCommand(string1);
		btn1.addActionListener(this);

		c.anchor = GridBagConstraints.NORTHWEST;
		c.fill = GridBagConstraints.BOTH;
		c.weightx = 1d;
		c.weighty = 1d;
		c.weighty = 1; // When you add the weight for some reason it anchors it
						// to the upper left
		c.weightx = 1;
		c.gridx = 0;
		c.gridy = 0;
		add(btn1, c);

		JRadioButton btn2 = new JRadioButton(string2);
		btn2.setActionCommand(string2);
		btn2.addActionListener(this);
		btn2.setEnabled(true);
		c.gridx = 1;
		c.gridy = 0;
		add(btn2, c);

		JRadioButton btn3 = new JRadioButton(string3);
		btn3.setActionCommand(string3);
		btn3.addActionListener(this);
		c.gridx = 2;
		c.gridy = 0;
		add(btn3, c);

		ButtonGroup group = new ButtonGroup();
		group.add(btn1);
		group.add(btn2);
		group.add(btn3);

	} // end of constructor

	@Override
	/** Listens to the radio buttons. */
	public void actionPerformed(ActionEvent e) {
		if (string1.compareTo(e.getActionCommand()) == 0) {

			if (microarrayPanel != null) {
				remove(microarrayPanel);

				revalidate();
				repaint();
			}
			microarrayPanel = new Microarray(customer);
			c.gridx = 0;
			c.gridy = 1;
			add(microarrayPanel, c);

		} else if (string2.compareTo(e.getActionCommand()) == 0) {
			remove(microarrayPanel);
			revalidate();
			repaint();

		} else if (string3.compareTo(e.getActionCommand()) == 0) {
			if (microarrayPanel != null) {
				remove(microarrayPanel);
				revalidate();
				repaint();
			}
		} else {
			System.out.println("Bad compare on radio button");
		}

	} // end of action listen
}
